package top.jnaw.jee.platform.controller.basics.extend;

import com.jfinal.core.Controller;
import java.util.List;
import top.jnaw.jee.platform.Consts.Result;
import top.jnaw.jee.platform.model.Files;
import top.jnaw.jee.utils.ModelResult;
import top.jnaw.jee.utils.qiniu.QiniuUtil;

public class QiniuController extends Controller {


  public void uploadAll() {
    ModelResult result = new ModelResult(Result.kBadParam);
    List<Files> filesList = Files.dao.find("select * from files");
    if (null != filesList && filesList.size() > 0) {
      if (QiniuUtil.uploadFile(filesList)) {
        result.setResult(Result.kSuccess);
      }
    }
    renderJson(result.toJson());
  }

  public void uploadOne() {
    ModelResult result = new ModelResult(Result.kBadParam);
    List<Files> filesList = Files.dao.find("select * from files where id=18");
    if (null != filesList && filesList.size() > 0) {
      if (QiniuUtil.uploadFile(filesList)) {
        result.setResult(Result.kSuccess);
      }
    }
    renderJson(result.toJson());
  }
}
